using System;
using System.Data;
using System.Collections.Generic;
using LabMS.Model;
using Maticsoft.DBUtility;
using System.Data.SqlClient;
using System.Text;

namespace ExtendBLL
{
    public class QueryItem
    {
        private readonly LabMS.DAL.Arrangement dal = new LabMS.DAL.Arrangement();
        public List<ExtendModule.QueryItem> GetModelList(string strWhere) 
        {




            StringBuilder strSql = new StringBuilder();
            if (!string.IsNullOrEmpty(strWhere)) 
            {
                strSql.Append(strWhere);
            }
            string strSql1 = " order by CourseID asc, LocationID asc,TeacherID asc ,Lession asc ,Week asc ";
            strSql.Append(strSql1);

            DataSet ds = dal.GetList(strSql.ToString());
            List<ExtendModule.QueryItem> modelList = new List<ExtendModule.QueryItem>();
            int rowsCount = ds.Tables[0].Rows.Count;
            if (rowsCount > 0)
            {
                ExtendModule.QueryItem model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new ExtendModule.QueryItem();
                    if (ds.Tables[0].Rows[n]["ID"].ToString() != "")
                    {
                        model.ID = int.Parse(ds.Tables[0].Rows[n]["ID"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["LocationID"].ToString() != "")
                    {
                        model.LocationID = int.Parse(ds.Tables[0].Rows[n]["LocationID"].ToString());
                    }
                    model.LocationName = ds.Tables[0].Rows[n]["LocationName"].ToString();
                    if (ds.Tables[0].Rows[n]["LabID"].ToString() != "")
                    {
                        model.LabID = int.Parse(ds.Tables[0].Rows[n]["LabID"].ToString());
                    }
                    model.LabName = ds.Tables[0].Rows[n]["LabName"].ToString();
                    model.Week = ds.Tables[0].Rows[n]["Week"].ToString();
                    model.TeacherName = ds.Tables[0].Rows[n]["TeacherName"].ToString();
                    if (ds.Tables[0].Rows[n]["Lession"].ToString() != "")
                    {
                        model.Lession = int.Parse(ds.Tables[0].Rows[n]["Lession"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["ChoosenClassID"].ToString() != "")
                    {
                        model.ChoosenClassID = int.Parse(ds.Tables[0].Rows[n]["ChoosenClassID"].ToString());
                    }
                    model.ClassName = ds.Tables[0].Rows[n]["ClassName"].ToString();
                    model.ScoreTerm = ds.Tables[0].Rows[n]["ScoreTerm"].ToString();
                    model.Year = ds.Tables[0].Rows[n]["Year"].ToString();
                    if (ds.Tables[0].Rows[n]["WeekDay"].ToString() != "")
                    {
                        model.WeekDay = int.Parse(ds.Tables[0].Rows[n]["WeekDay"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["CourseProjectID"].ToString() != "")
                    {
                        model.CourseProjectID = int.Parse(ds.Tables[0].Rows[n]["CourseProjectID"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["CourseTeacherID"].ToString() != "")
                    {
                        model.CourseTeacherID = int.Parse(ds.Tables[0].Rows[n]["CourseTeacherID"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["ClassID"].ToString() != "")
                    {
                        model.ClassID = int.Parse(ds.Tables[0].Rows[n]["ClassID"].ToString());
                    }
                    model.ProjectName = ds.Tables[0].Rows[n]["ProjectName"].ToString();
                    model.ProjectCode = ds.Tables[0].Rows[n]["ProjectCode"].ToString();
                    model.ArrangeType = ds.Tables[0].Rows[n]["ArrangeType"].ToString();
                    if (ds.Tables[0].Rows[n]["TeacherID"].ToString() != "")
                    {
                        model.TeacherID = int.Parse(ds.Tables[0].Rows[n]["TeacherID"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
            
        }
    }
}
